home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT19.ZIP / FIRE.ASM next >
Assembly Source File  |  1995-02-21  |  8KB  |  218 lines

  1.     DOSSEG          ; Order the program to order it's segments in the
  2.                     ; same way that high level languages do.
  3.  
  4.     .MODEL SMALL    ; Different models :
  5.                     ;     Tiny   : Code + Data < 64k  (can be made a COM file)
  6.                     ;     Small  : Code < 64k ;  Data < 64k
  7.                     ;     Medium : Code > 64k ;  Data < 64k
  8.                     ;     Compact: Code < 64k ;  Data > 64k
  9.                     ;     Large  : Code > 64k ;  Data > 64k
  10.                     ;     Huge   : Arrays > 64k
  11.  
  12.     .286            ; Enable 286 instructions
  13.  
  14.     .STACK 200h
  15.  
  16.     .DATA           ; Tells compiler that data is to follow.
  17.  
  18. endmessage db "This was the Fire Effect       - denthor@beastie.cs.und.ac.za$"
  19.                     ; This is our end message. Must be terminated with a "$"
  20. xsize    =  80      ; The x-width of our screen in pixels
  21. ysize    =  112      ; The y-height of our screen in pixels, plus a few extra
  22. randseed dw ?       ; any number for randomness
  23.  
  24. pallette db  0, 0, 0, 0, 0, 6, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 8, 0, 0, 9, 0, 0,10
  25.          db  2, 0,10, 4, 0, 9, 6, 0, 9, 8, 0, 8,10, 0, 7,12, 0, 7,14, 0, 6,16, 0, 5
  26.          db 18, 0, 5,20, 0, 4,22, 0, 4,24, 0, 3,26, 0, 2,28, 0, 2,30, 0, 1,32, 0, 0
  27.          db 32, 0, 0,33, 0, 0,34, 0, 0,35, 0, 0,36, 0, 0,36, 0, 0,37, 0, 0,38, 0, 0
  28.          db 39, 0, 0,40, 0, 0,40, 0, 0,41, 0, 0,42, 0, 0,43, 0, 0,44, 0, 0,45, 0, 0
  29.          db 46, 1, 0,47, 1, 0,48, 2, 0,49, 2, 0,50, 3, 0,51, 3, 0,52, 4, 0,53, 4, 0
  30.          db 54, 5, 0,55, 5, 0,56, 6, 0,57, 6, 0,58, 7, 0,59, 7, 0,60, 8, 0,61, 8, 0
  31.          db 63, 9, 0,63, 9, 0,63,10, 0,63,10, 0,63,11, 0,63,11, 0,63,12, 0,63,12, 0
  32.          db 63,13, 0,63,13, 0,63,14, 0,63,14, 0,63,15, 0,63,15, 0,63,16, 0,63,16, 0
  33.          db 63,17, 0,63,17, 0,63,18, 0,63,18, 0,63,19, 0,63,19, 0,63,20, 0,63,20, 0
  34.          db 63,21, 0,63,21, 0,63,22, 0,63,22, 0,63,23, 0,63,24, 0,63,24, 0,63,25, 0
  35.          db 63,25, 0,63,26, 0,63,26, 0,63,27, 0,63,27, 0,63,28, 0,63,28, 0,63,29, 0
  36.          db 63,29, 0,63,30, 0,63,30, 0,63,31, 0,63,31, 0,63,32, 0,63,32, 0,63,33, 0
  37.          db 63,33, 0,63,34, 0,63,34, 0,63,35, 0,63,35, 0,63,36, 0,63,36, 0,63,37, 0
  38.          db 63,38, 0,63,38, 0,63,39, 0,63,39, 0,63,40, 0,63,40, 0,63,41, 0,63,41, 0
  39.          db 63,42, 0,63,42, 0,63,43, 0,63,43, 0,63,44, 0,63,44, 0,63,45, 0,63,45, 0
  40.          db 63,46, 0,63,46, 0,63,47, 0,63,47, 0,63,48, 0,63,48, 0,63,49, 0,63,49, 0
  41.          db 63,50, 0,63,50, 0,63,51, 0,63,52, 0,63,52, 0,63,52, 0,63,52, 0,63,52, 0
  42.          db 63,53, 0,63,53, 0,63,53, 0,63,53, 0,63,54, 0,63,54, 0,63,54, 0,63,54, 0
  43.          db 63,54, 0,63,55, 0,63,55, 0,63,55, 0,63,55, 0,63,56, 0,63,56, 0,63,56, 0
  44.          db 63,56, 0,63,57, 0,63,57, 0,63,57, 0,63,57, 0,63,57, 0,63,58, 0,63,58, 0
  45.          db 63,58, 0,63,58, 0,63,59, 0,63,59, 0,63,59, 0,63,59, 0,63,60, 0,63,60, 0
  46.          db 63,60, 0,63,60, 0,63,60, 0,63,61, 0,63,61, 0,63,61, 0,63,61, 0,63,62, 0
  47.          db 63,62, 0,63,62, 0,63,62, 0,63,63, 0,63,63, 1,63,63, 2,63,63, 3,63,63, 4
  48.          db 63,63, 5,63,63, 6,63,63, 7,63,63, 8,63,63, 9,63,63,10,63,63,10,63,63,11
  49.          db 63,63,12,63,63,13,63,63,14,63,63,15,63,63,16,63,63,17,63,63,18,63,63,19
  50.          db 63,63,20,63,63,21,63,63,21,63,63,22,63,63,23,63,63,24,63,63,25,63,63,26
  51.          db 63,63,27,63,63,28,63,63,29,63,63,30,63,63,31,63,63,31,63,63,32,63,63,33
  52.          db 63,63,34,63,63,35,63,63,36,63,63,37,63,63,38,63,63,39,63,63,40,63,63,41
  53.          db 63,63,42,63,63,42,63,63,43,63,63,44,63,63,45,63,63,46,63,63,47,63,63,48
  54.          db 63,63,49,63,63,50,63,63,51,63,63,52,63,63,52,63,63,53,63,63,54,63,63,55
  55.          db 63,63,56,63,63,57,63,63,58,63,63,59,63,63,60,63,63,61,63,63,62,63,63,63
  56.            ; Our pallette ... generated elsewhere and brought in
  57.  
  58. screen   db xsize*ysize dup (?) ; Virtual screen
  59.  
  60.     .CODE           ; Tells compiler that code is to follow.
  61.  
  62.  
  63. Random          proc near
  64.  
  65.     mov     ax,[RandSeed]
  66.     mov     dx,8405h
  67.     mul     dx     ; ax*dx with result in dx:ax
  68.     inc     ax
  69.     mov     [RandSeed],ax
  70.     ret            ; Return back to main section
  71.  
  72. Random          endp
  73.  
  74.  
  75.  
  76. SetUpScreen     proc near
  77.  
  78.     mov     ax,0013h
  79.     int     10h       ; Get into 320x200x256 MCGA mode.
  80.  
  81.     mov     ax,0a000h
  82.     mov     es,ax
  83.     xor     di,di     ; ES:DI is now pointing to the top left hand of the screen
  84.  
  85.     cli
  86.     cld
  87.     mov     dx,3c4h
  88.     mov     ax,604h   ; Enter unchained mode
  89.     out     dx,ax
  90.     mov     ax,0F02h  ; All planes
  91.     out     dx,ax
  92.     xor     ax,ax
  93.     mov     cx,32767
  94.     rep     stosw     ; Clear the screen
  95.     mov     dx,3D4h
  96.     mov     ax,14h    ; Disable dword mode
  97.     out     dx,ax
  98.     mov     ax,0E317h ; Enable byte mode.
  99.     out     dx,ax
  100.     out     dx,ax
  101.     mov     ax,00409h ; Cell height
  102.     out     dx,ax
  103.  
  104.     mov     si, offset [pallette]
  105.     mov     dx, 3c8h  ; Pallette write register
  106.     mov     al, 0
  107.     out     dx, al    ; Start at color zero
  108.     inc     dx
  109.     mov     cx, 768
  110. @PalLoop :
  111.     outsb             ; Write value to port; inc DI
  112.     dec     cx
  113.     jnz     @PalLoop
  114.     ret
  115.  
  116. SetUpScreen    endp
  117.  
  118.  
  119.  
  120. START:
  121.     mov     ax,@DATA
  122.     mov     ds,ax     ; Moves the segment of the data into DS.
  123.  
  124.     call    SetUpScreen
  125.  
  126.     mov     randseed,1234h
  127.     mov     si,offset [screen]
  128.     mov     cx,xsize*ysize
  129.     xor     ax,ax
  130.     rep     stosb     ; Clear our virtual screen.
  131.  
  132. @MainLoop :
  133.  
  134.                       ;
  135.                       ; This next bit puts either 0 or 255 along the very
  136.                       ; bottom row of our virtual screen.
  137.                       ;
  138.  
  139.     mov     si,offset [screen]
  140.     add     si,xsize*ysize
  141.     sub     si,xsize  ; si=ofs(screen)+xsize*ysize-xsize ie. start of last row
  142.     mov     cx,xsize  ; loop the entire last row
  143.     xor     dx,dx
  144. @Newline :
  145.     call    random
  146.     mov     ds:[si],dl
  147.     inc     si
  148.     dec     cx
  149.     jnz     @Newline
  150.  
  151.                       ;
  152.                       ; This "softens" the values in the virtual array,
  153.                       ; creating a fire effect.
  154.                       ;
  155.     mov     cx,xsize*ysize
  156.     sub     cx,xsize
  157.     mov     si,offset [screen]
  158.     add     si,xsize
  159. @FileLoop :
  160.     xor     ax,ax
  161.     mov     al,ds:[si]
  162.     add     al,ds:[si+1]
  163.     adc     ah,0
  164.     add     al,ds:[si-1]
  165.     adc     ah,0
  166.     add     al,ds:[si+xsize]
  167.     adc     ah,0
  168.     shr     ax,2
  169.     jz      @zero
  170.     dec     ax
  171. @Zero :
  172.                       ; al = ((pos)+(pos+1)+(pos-1)+(pos+80))/4 - 1
  173.     mov     ds:[si-xsize],al
  174.     inc     si
  175.     dec     cx
  176.     jnz     @FileLoop
  177.  
  178.                       ;
  179.                       ; This dumps our virtual screen to the VGA screen.
  180.                       ;
  181.     mov     dx, 3dah
  182. l1:
  183.     in      al, dx
  184.     and     al, 8h
  185.     jnz     l1
  186. l2:
  187.     in      al, dx
  188.     and     al, 8h
  189.     jz      l2
  190.  
  191.     mov     cx,xsize*ysize
  192.     shr     cx,1
  193.     mov     si,offset [screen]
  194.     xor     di,di
  195.     rep     movsw
  196.  
  197.     mov     ah,01
  198.     int     16h       ; Has a key been pressed?
  199.     jz      @MainLoop ; If not, carry on.
  200.  
  201.     mov     ah,0
  202.     int     16h       ;get a key, returned in AX
  203.                       ;this is just to clear the keyboard buffer of the key
  204.                       ;press.
  205.  
  206.     mov     ax,0003h
  207.     int     10h       ; Get into 80x25 text mode
  208.  
  209.     mov     dx,offset [endmessage]
  210.     mov     ah,09h
  211.     int     21h       ; Dos interrupt 21, subfunction 09 ... print string.
  212.                       ; DS:DX must be pointing to start of string.
  213.  
  214.     mov     ax,4c00h  ; This function exits the program
  215.     int     21h       ; and returns control to DOS.
  216. END START
  217.  
  218.